//
//  MyInfoTableViewController.m
//  Mtime2.0
//
//  Created by 凉气的Mac on 16/9/3.
//  Copyright © 2016年 凉气的Mac. All rights reserved.
//

#import "MyInfoTableViewController.h"

#import "MyInfoHeaderView.h"

#import "MyInfoTableViewCell.h"

#import "MyInfoModel.h"

#import "MyInfoFooterView.h"

#import "SeedbackViewController.h"

@interface MyInfoTableViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)  NSArray *modelArray;

@property(nonatomic,weak)  UIImageView *message;

@property(nonatomic,weak)  UITableView *tableView;

@end

@implementation MyInfoTableViewController

-(NSArray *)modelArray{

    if (_modelArray == nil) {
        
        _modelArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Setting.plist" ofType:nil]];
        
    }
    
    return _modelArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
        
    }];
    
    self.tableView = tableView;
    
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    self.tableView.tableHeaderView = [[MyInfoHeaderView alloc]initWithFrame:CGRectMake(0, 0, 0, 130)];
    
    [self.tableView registerClass:[MyInfoTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.tableView.tableFooterView = [[MyInfoFooterView alloc]initWithFrame:CGRectMake(0, 0, 0, 80)];
    
    
    [self setupNavigationBar];
}

-(void)viewDidAppear:(BOOL)animated{

    self.message.hidden = NO;
    
    [super viewDidAppear:animated];
}

-(void)setupNavigationBar{

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"menu_top_bg"] forBarMetrics:UIBarMetricsDefault];
    
    UIImageView *message = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_my_message"]];
    
    self.message = message;

    
    [self.view addSubview:message];

    [message mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).offset(25);
        
        make.right.equalTo(self.view).offset(-25);
        
    }];
    
    


}

//-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//
//    self.navigationController.navigationBar.alpha = scrollView.contentOffset.y / 50;
//    
//    if (scrollView.contentOffset.y < -20) {
//        
//        scrollView.contentOffset = CGPointMake(0, -20);
//        
//    }
//    
//    
//
//}

#pragma mark --
#pragma mark --dataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    
    NSDictionary *dict = self.modelArray[section];
    
    NSArray *groups = dict[@"groups"];
    
    return groups.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell;
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell1"];
        
    }
    
    if (indexPath.section == 1 || indexPath.section == 2) {
        
       NSDictionary *dict = self.modelArray[indexPath.section];
        
        NSArray *groups = dict[@"groups"];
        
        NSDictionary *cellDict = groups[indexPath.row];
        
        UIImage *image = [UIImage imageNamed:cellDict[@"image"]];
        
        cell.imageView.image = image;
        
        cell.textLabel.text = cellDict[@"title"];
       
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }
    
    if (indexPath.section == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    }
    
    return cell;
}


#pragma mark --
#pragma mark --delegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    
    SeedbackViewController *vc = [[SeedbackViewController alloc]init];
    
    [self.navigationController pushViewController:vc animated:YES];
    
 
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        
        return 90;
    }else{
    
        return 60;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 1;
}

@end


































